using System;
using System.Collections.Generic;
using Sustainalytics.CRT.Synchronization;
using Sustainalytics.Entities.ESGRatings;
using Xunit;
using System.Threading.Tasks;

namespace Sustainalytics.CRT.Synchronization.Tests
{
    [Trait("Category", "Unit")]
    public class FocusedRatingsPercentileTest
    {

        private readonly IList<EsgFocusPercentileThreshold> _thresholds;

        public FocusedRatingsPercentileTest()
        {
            this._thresholds = new List<EsgFocusPercentileThreshold>
                                   {
                                       new EsgFocusPercentileThreshold { Id = Guid.NewGuid(), Value = 1f, PeerGroup = "Homebuilders", PeerGroupId = new Guid("0BFA13EB-A628-4178-AC02-D99D077BCF53"), LowerBound = 0, UpperBound = 25 },
                                       new EsgFocusPercentileThreshold { Id = Guid.NewGuid(), Value = 0.75f, PeerGroup = "Homebuilders", PeerGroupId = new Guid("0BFA13EB-A628-4178-AC02-D99D077BCF53"), LowerBound = 25, UpperBound = 50 },
                                       new EsgFocusPercentileThreshold { Id = Guid.NewGuid(), Value = 0.50f, PeerGroup = "Homebuilders", PeerGroupId = new Guid("0BFA13EB-A628-4178-AC02-D99D077BCF53"), LowerBound = 50, UpperBound = 75 },
                                       new EsgFocusPercentileThreshold { Id = Guid.NewGuid(), Value = 0.25f, PeerGroup = "Homebuilders", PeerGroupId = new Guid("0BFA13EB-A628-4178-AC02-D99D077BCF53"), LowerBound = 75, UpperBound = 101 },
                                   };
        }

        [Fact]
        public async Task Should_return_a_percentile_when_for_a_score_in_first_range()
        {
            var actual =
               await FocusedRatingsPercentileManager.GetPercentile(10, _thresholds);
            var expected = 100f;
            Assert.Equal(expected, actual);
        }


        [Theory,
         InlineData(-0.01f),
         InlineData(101f)]
        public async Task Should_return_NAN_when_Score_not_in_any_gap(float score)
        {
            var actual = await FocusedRatingsPercentileManager.GetPercentile(score, _thresholds);
            var expected = float.NaN;
            Assert.Equal(expected, actual);
        }


    }

}